package com.game.server;

import java.util.HashMap;

public final class Session {
	private final HashMap<String, Object> map;

	private final String sessionID;

	private Session(String sessionID) {
		map = new HashMap<String, Object>();
		this.sessionID = sessionID;
	}

	public void put(String key, Object value) {
		map.put(key, value);
	}

	public void remove(String key) {
		map.remove(key);
	}

	public Object get(String key) {
		return map.get(key);
	}

	public String getSessionID() {
		return sessionID;
	}

	private static HashMap<String, Session> sessionMap;

	public static Session getSession(String sessionID) {
		if (sessionMap == null) {
			sessionMap = new HashMap<String, Session>();
		}
		Session session = sessionMap.get(sessionID);
		if (session == null) {
			session = new Session(sessionID);
			sessionMap.put(sessionID, session);
		}
		return session;
	}

	public static void removeSession(String sessionID) {
		sessionMap.remove(sessionID);
	}

}
